using System;
using System.IO;
using System.Reflection;
using ThoughtWorks.TreeSurgeon.Core;

namespace ThoughtWorks.TreeSurgeon.TreeSurgeonConsole
{
	internal class TreeSurgeonConsoleMain
	{
		[STAThread]
		private static int Main(string[] args)
		{
			try
			{
				return RunApp(args);
			}
			catch (Exception e)
			{
				Console.WriteLine("Unhandled Exception thrown. Details follow: ");
				Console.WriteLine(e.Message);
				Console.WriteLine(e.StackTrace);
				return -1;
			}
		}

		private static int RunApp(string[] args)
		{
			Console.WriteLine("TreeSurgeon version 1.0");
			Console.WriteLine("Copyright (C) 2005 Mike Roberts, ThoughtWorks, Inc");
			Console.WriteLine();
			if (args.Length != 1)
			{
				Usage();
				return -1;
			}
			Console.WriteLine("Starting Tree Generation for " + args[0]);
			Console.WriteLine();
			string outputDirectory = new TreeSurgeonFrontEnd(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).GenerateDevelopmentTree(args[0]);
			Console.WriteLine("Tree Generation complete. Files can be found at " + outputDirectory);
			return 0;
		}

		private static void Usage()
		{
			Console.WriteLine("Creates a .NET Development tree");
			Console.WriteLine();
			Console.WriteLine("TreeSurgeon projectName");
			Console.WriteLine();
			Console.WriteLine("Please note - project name must not contain spaces. We recommend you use CamelCase for project names.");
		}
	}
}